

define(['vue','moment','config','common','../model/upLoadList'],function(Vue,moment,config,utils,upLoadList){
	'use strict';

	var PointsDetailView = new Vue({
		el:'#app',
		data:{
			list:'',	
			page: 1,
			totalPage:0,
			isLoadMore:0
		},
		filters: {
		  moment: function (date) {
		    return moment(date).format('MM-DD');
		  }
		 
		},
		created:function(){	
			var _this=this;
			var pageSize = 15;
			var data = {
				page: _this.page,
				pageSize: pageSize,
				integralType:2
			}
			upLoadList(utils.getWebUrl('integralRecord/list'),data,function(res){
				_this.list = res.data.list;
				_this.totalPage = res.data.totalPage;
				_this.page++;
				//积分来源1直接消费2消费推荐3销售4销售推荐5升级6激励E积分7转化成享积分8升级推荐
				for (var i = _this.list.length - 1; i >= 0; i--) {
					if(_this.list[i].sourceType==1){
						_this.list[i].sourceType="直接消费";
					}else if(_this.list[i].sourceType==2){
						_this.list[i].sourceType="消费推荐";
					}else if(_this.list[i].sourceType==3){
						_this.list[i].sourceType="销售";
					}else if(_this.list[i].sourceType==4){
						_this.list[i].sourceType="销售推荐";
					}else if(_this.list[i].sourceType==5){
						_this.list[i].sourceType="升级";
					}else if(_this.list[i].sourceType==6){
						_this.list[i].sourceType="激励E积分";
					}else if(_this.list[i].sourceType==7){
						_this.list[i].sourceType="转化成享积分";
					}else if(_this.list[i].sourceType==8){
						_this.list[i].sourceType="升级推荐";
					}
					if(_this.list[i].revenueExpenditureType==1){
						_this.list[i].integralValue="+"+_this.list[i].integralValue;	
					}else if(_this.list[i].revenueExpenditureType==2){
						_this.list[i].integralValue="-"+_this.list[i].integralValue;
					}
				}
			})



			/*var _this = this;
			var data = {
				page: 1,
				pageSize: 10,
				integralType:2
			}

			utils.ajax(utils.getWebUrl('/integralRecord/list'),data,'POST',function(res){
				_this.list = res.data.list;

				//积分来源1直接消费2消费推荐3销售4销售推荐5升级6激励E积分7转化成享积分8升级推荐
				for (var i = _this.list.length - 1; i >= 0; i--) {
					if(_this.list[i].sourceType==1){
						_this.list[i].sourceType="直接消费";
					}else if(_this.list[i].sourceType==2){
						_this.list[i].sourceType="消费推荐";
					}else if(_this.list[i].sourceType==3){
						_this.list[i].sourceType="销售";
					}else if(_this.list[i].sourceType==4){
						_this.list[i].sourceType="销售推荐";
					}else if(_this.list[i].sourceType==5){
						_this.list[i].sourceType="升级";
					}else if(_this.list[i].sourceType==6){
						_this.list[i].sourceType="激励E积分";
					}else if(_this.list[i].sourceType==7){
						_this.list[i].sourceType="转化成享积分";
					}else if(_this.list[i].sourceType==8){
						_this.list[i].sourceType="升级推荐";
					}
					if(_this.list[i].revenueExpenditureType==1){
						_this.list[i].integralValue="+"+_this.list[i].integralValue;	
					}else if(_this.list[i].revenueExpenditureType==2){
						_this.list[i].integralValue="-"+_this.list[i].integralValue;
					}
				}	


			})*/
		},
		directives: {
		  scroll: {
		    bind: function (el, binding){
		      window.addEventListener('scroll',function() {
		       		var fnc = binding.value;   
   					fnc();
		      })
		    }
		  }
		},
		//判定事件
		methods:{
			loadMore:function(event){

				var _this = this;
				var pageSize = parseInt(Math.ceil(($('body').height()-$('.headTitle').height()-$('.title').height())/$('.list li').height()), 10);
				if (($(document).scrollTop() >= $(document).height() - $(window).height())&&_this.page<_this.totalPage) {
					var data = {
						page: _this.page,
						pageSize: pageSize,
						integralType:2
					}
					upLoadList(utils.getWebUrl('integralRecord/list'),data,function(res){
						
						//积分来源1直接消费2消费推荐3销售4销售推荐5升级6激励E积分7转化成享积分8升级推荐
						for (var i = res.data.list.length - 1; i >= 0; i--) {
							if(res.data.list[i].sourceType==1){
								res.data.list[i].sourceType="直接消费";
							}else if(res.data.list[i].sourceType==2){
								res.data.list[i].sourceType="消费推荐";
							}else if(res.data.list[i].sourceType==3){
								res.data.list[i].sourceType="销售";
							}else if(res.data.list[i].sourceType==4){
								res.data.list[i].sourceType="销售推荐";
							}else if(res.data.list[i].sourceType==5){
								res.data.list[i].sourceType="升级";
							}else if(res.data.list[i].sourceType==6){
								res.data.list[i].sourceType="激励E积分";
							}else if(res.data.list[i].sourceType==7){
								res.data.list[i].sourceType="转化成享积分";
							}else if(res.data.list[i].sourceType==8){
								res.data.list[i].sourceType="升级推荐";
							}
							if(res.data.list[i].revenueExpenditureType==1){
								res.data.list[i].integralValue="+"+res.data.list[i].integralValue;	
							}else if(res.data.list[i].revenueExpenditureType==2){
								res.data.list[i].integralValue="-"+res.data.list[i].integralValue;
							}
						}
						_this.list = _this.list.concat(res.data.list);
						_this.page++;
					})
		        }
			}
		}
		
	});


	return PointsDetailView
});
